﻿Imports BUS
Imports DTO
Public Class TimKiemDocGia


    Private dgCrt As New DocGiaCrt()

    Private Sub CheckBoxngaysinh_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxngaysinh.CheckedChanged
        dtpngaysinhtu.Enabled = CheckBoxngaysinh.Checked
        dtpngaysinhden.Enabled = CheckBoxngaysinh.Checked
    End Sub


    Private Sub CheckBoxdiachi_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxdiachi.CheckedChanged
        txtdiachi_tcdocgia.Enabled = CheckBoxdiachi.Checked
    End Sub

    Private Sub CheckBoxemail_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxemail.CheckedChanged
        txtemail_tcdocgia.Enabled = CheckBoxemail.Checked
    End Sub

    Private Sub CheckBoxngaylapthe_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxngaylapthe.CheckedChanged
        dtpngaylapthe.Enabled = CheckBoxngaylapthe.Checked
    End Sub
    Private Sub cbLoaiDocGia_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxLoaiDocGia.CheckedChanged
        cbbloaidocgia.Enabled = CheckBoxLoaiDocGia.Checked
    End Sub

    Private Sub LoadLoaiDocGia()
        Dim ldgBus As New LoaiDocGiaBUS
        Dim ds As List(Of LoaiDocGiaDTO)
        ds = ldgBus.LayDanhSach()
        cbbloaidocgia.DataSource = ds
        cbbloaidocgia.ValueMember = "MaLoaiDocGia"
        cbbloaidocgia.DisplayMember = "TenDocGia"

    End Sub

    Private Sub CapNhatTieuChiTraCuu(ByVal bUpDate As Boolean)
        If (bUpDate) Then
            If (txtmadocgia_tcdocgia.Text <> "") Then
                dgCrt.MaDocGia = Integer.Parse(txtmadocgia_tcdocgia.Text)
            Else
                dgCrt.MaDocGia = 0
            End If
            dgCrt.HoTen = txthovaten_tcdocgia.Text
            dgCrt.DiaChi = txtdiachi_tcdocgia.Text
            dgCrt.Email = txtemail_tcdocgia.Text
            dgCrt.NgaySinhTu = dtpngaysinhtu.Value
            dgCrt.NgaySinhDen = dtpngaysinhden.Value
            dgCrt.NgayLapThe = dtpngaylapthe.Value
            dgCrt.MaLoaiDocGia = cbbloaidocgia.SelectedValue
            dgCrt.CheckDiaChi = CheckBoxdiachi.Checked
            dgCrt.CheckEmail = CheckBoxemail.Checked
            dgCrt.CheckNgaySinh = CheckBoxngaysinh.Checked
            dgCrt.CheckNgayLapThe = CheckBoxngaylapthe.Checked
            dgCrt.CheckMaLoaiDocGia = CheckBoxLoaiDocGia.Checked
        Else
            If dgCrt.MaDocGia <> 0 Then
                txtmadocgia_tcdocgia.Text = dgCrt.MaDocGia.ToString()

            End If
            txthovaten_tcdocgia.Text = dgCrt.HoTen
            'dtpngaysinhtu.Value = dgCrt.NgaySinhTu.Date
            'dtpngaysinhden.Value = dgCrt.NgaySinhDen.Date
            txtdiachi_tcdocgia.Text = dgCrt.DiaChi
            txtemail_tcdocgia.Text = dgCrt.Email
            'dtpngaylapthe.Value = dgCrt.NgayLapThe.Date
            CheckBoxngaysinh.Checked = dgCrt.CheckNgaySinh
            CheckBoxemail.Checked = dgCrt.CheckEmail
            CheckBoxngaylapthe.Checked = dgCrt.CheckNgayLapThe
            CheckBoxdiachi.Checked = dgCrt.CheckDiaChi

        End If
    End Sub

    Private Sub TimKiemDocGia_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            LoadLoaiDocGia()
            dgCrt = New DocGiaCrt()
            CapNhatTieuChiTraCuu(False)
            Dim dtDG As New DataTable()
            DataGridViewtracuudocgia.DataSource = dtDG

        Catch ex As Exception
            MessageBox.Show(ex.Message)

        End Try
    End Sub

    Private Sub btntracua_tcdocgia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntracua_tcdocgia.Click
        Try
            CapNhatTieuChiTraCuu(True)
            Dim dgBus As New DocGiaBUS_1()
            Dim dtDG As DataTable
            dtDG = dgBus.TimKiem(dgCrt)
            DataGridViewtracuudocgia.DataSource = dtDG
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnthoat_tcsach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat_tcsach.Click
        Close()
    End Sub

    
End Class